<%--
  Created by IntelliJ IDEA.
  User: lt
  Date: 2018/5/24
  Time: 20:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>

<title>采购 - 采购审核</title>
<link rel="stylesheet" href="${contextPath}/static/ace/components/_mod/jquery-ui/jquery-ui.css"/>
<link rel="stylesheet" href="${contextPath}/static/ace/components/bootstrap-datepicker/dist/css/bootstrap-datepicker3.css"/>
<link rel="stylesheet" href="${contextPath}/static/ace/components/_mod/jqgrid/ui.jqgrid.css"/>
<%-- <jsp:include page="../../../head.jsp"/> --%>
<link rel="stylesheet" href="${contextPath}/static/bootstrap/css/bootstrap-select.css" />
<link rel="stylesheet" href="${contextPath}/static/ztree/css/zTreeStyle.css" />
<script src="${contextPath}/static/bootstrap/js/bootstrap-select.min.js"></script>
<script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.min.js"></script>
<script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="${contextPath}/static/countjs/regularYz.js"></script>


<style type="text/css">
    .customBtn {
        line-height: 20px;
        margin-bottom: 3px;
    }
.bootstrap-select > .btn{
		color:#ABBAC3 !important;
		background-color: #fff !important;
		text-shadow:none;
		border-width:1px;
	}
	.bootstrap-select > .btn:hover, .bootstrap-select > .btn:focus:hover, .bootstrap-select > .btn.focus:hover, .bootstrap-select > .btn:active:hover, .bootstrap-select > .btn:focus:active, .btn-default:focus:active, .open > .btn.dropdown-toggle, .open > .btn-default.dropdown-toggle, .open > .btn.dropdown-toggle:hover, .open > .btn-default.dropdown-toggle:hover, .open > .btn.dropdown-toggle:focus, .open > .btn-default.dropdown-toggle:focus, .open > .btn.dropdown-toggle.focus, .open > .btn-default.dropdown-toggle.focus, .open > .btn.dropdown-toggle:active, .open > .btn-default.dropdown-toggle:active {
	    background-color: #fff !important;
	    border-color: #ABBAC3;
	}
    .btnLine {
        margin-left: 1px;
        margin-top: 8px;
        margin-bottom: 2px;
    }

    @-webkit-keyframes bouncedelay {
        0%, 80%, 100% {
            -webkit-transform: scale(0.0)
        }
        40% {
            -webkit-transform: scale(1.0)
        }
    }

    @keyframes bouncedelay {
        0%, 80%, 100% {
            transform: scale(0.0);
            -webkit-transform: scale(0.0);
        }
        40% {
            transform: scale(1.0);
            -webkit-transform: scale(1.0);
        }
    }

    .autocomplete-suggestions {
        border: 1px solid #999;
        background: #FFF;
        overflow: auto;
    }

    .autocomplete-suggestion {
        padding: 2px 5px;
        white-space: nowrap;
        overflow: hidden;
    }

    .autocomplete-selected {
        background: #F0F0F0;
    }

    .autocomplete-suggestions strong {
        font-weight: normal;
        color: #3399FF;
    }

    @-moz-document url-prefix() {
        fieldset {
            display: table-cell;
        }
    }

    .ui-jqgrid-sortable {
        text-align: center;
    }

    #cb_grid-table{margin-left: 10px;}
</style>
<div class="row" id="app">
    <div class="row btnLine">
        <div class="button-len col-sm-12">
            <div style="width: 100%; margin-bottom: 10px;">
                <button type="button" class="btn btn-white btn-sm btn-purple customBtn"  id="verpassBtn">通过</button>
                <button type="button" class="btn btn-white btn-info btn-sm customBtn" id="vernopassBtn">不通过</button>

                <select class="selectpicker" data-live-search="true" title="请选择店铺名称" data-live-search-placeholder="搜索" data-actions-box="true" id="shopName">
				</select>
				<input type="hidden" name="shopName" id="shopname" />
				<input type="hidden" name="shopIdName" id="shopIdName" />
                <button type="button" class="btn btn-sm btn-white btn-info search-len customBtn" id="psearch">
                    <i class="ace-icon fa fa-search orange"></i>搜索
                </button>
            </div>
        </div>
    </div>
    <!-- 内容数据开始 -->
    <div class="col-xs-12">
        <table id="grid-table"></table>

        <div id="grid-pager"></div>

    </div>

    <!-- 内容数据结束 -->



</div>
<!-- 数型内容 -->

<!-- page specific plugin scripts -->
<script type="text/javascript" src="${contextPath}/static/statistics/js/jquery.mockjax.js"></script>
<script type="text/javascript" src="${contextPath}/static/statistics/js/jquery.autocomplete.js"></script>
<script src=${contextPath}/static/layer/layui.all.js></script>
<script type="text/javascript" src="${contextPath}/static/ace/components/bootstrap-datepicker/dist/js/bootstrap-datepicker.js"></script>
<script type="text/javascript" src="${contextPath}/static/ace/components/jqGrid/js/jquery.jqGrid.js"></script>
<script type="text/javascript" src="${contextPath}/static/ace/components/jqGrid/js/i18n/grid.locale-cn.js"></script>
<script type="text/javascript" src="${contextPath}/static/layer/layer.js"></script>
<script type="text/javascript" src="${contextPath}/static/ztree/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="${contextPath}/static/ztree/js/jquery.ztree.excheck-3.5.js"></script>

<script type="text/javascript">
    var grid_selector = "#grid-table";
    var pager_selector = "#grid-pager";

    var grid_shop_selector = "#grid-shop-table";
    var pager_shop_selector = "#grid-shop-pager";

    var grid_prod_selector = "#grid-prod-table";
    var pager_prod_selector = "#grid-prod-pager";

    var laypage = layui.laypage,
        layer = layui.layer
    laydate = layui.laydate;

</script>
<!-- 缺货商品列表 -->
<script>

    var grid_data = '${id}';
    var scripts = [null, "${contextPath}/static/ace/components/bootstrap-datepicker/dist/js/bootstrap-datepicker.js", "${contextPath}/static/ace/components/jqGrid/js/jquery.jqGrid.js", "${contextPath}/static/ace/components/jqGrid/js/i18n/grid.locale-cn.js", "${contextPath}/static/layer/layer.js","${contextPath}/static/ztree/js/jquery.ztree.core-3.5.js", "${contextPath}/static/ztree/js/jquery.ztree.excheck-3.5.js", null]
    var getShopInStockItem = function () {
    	var filters = {};
        filters.limit = 10000;
        filters.offset = 0;
        filters.state = 0;
        filters.shopId = $("#shopName").val();
     $('.page-content-area').ace_ajax('loadScripts', scripts, function () {

        jQuery(function ($) {

            var parent_column = $(grid_selector).closest('[class*="col-"]');
            //resize to fit page size
            $(window).on('resize.jqGrid', function () {
                $(grid_selector).jqGrid('setGridWidth', parent_column.width());
            })

            //resize on sidebar collapse/expand
            $(document).on('settings.ace.jqGrid', function (ev, event_name, collapsed) {
                if (event_name === 'sidebar_collapsed' || event_name === 'main_container_fixed') {
                    setTimeout(function () {
                        $(grid_selector).jqGrid('setGridWidth', parent_column.width());
                    }, 20);
                }
            })
            jQuery(grid_selector).jqGrid({
                subGrid: false,
                url : '${contextPath}/order/getShopInStockItem',
                datatype: "json",
                mtype: 'POST',
                height: 500,
                postData: filters,
                colNames: ['id','订单编号','商品名称', '类别', '简码','单位','要货数量', '进价', '金额','申请人','申请时间'],
                colModel: [
					{
					    name: 'ID',
					    index: 'ID',
					    hidden: true
					},
                    {
                        name: 'OID',
                        index: 'OID'
                    },
                    {
                        name: 'PRODUCT_NAME',
                        index: 'PRODUCT_NAME'
                    },
                    {
                        name: 'TYPE_NAME',
                        index: 'TYPE_NAME'
                    },
                    {
                        name: 'SHORT_CODE',
                        index: 'SHORT_CODE'
                    },
                    {
                        name: 'UNIT',
                        index: 'UNIT'
                    },
                    {
                        name: 'QUANTITY',
                        index: 'QUANTITY'
                    },
                    {
                        name: 'CST_PRICE',
                        index: 'CST_PRICE'
                    },
                    {
                        name: 'IAMOUNT',
                        index: 'IAMOUNT'
                    },
                    {
                        name: 'USER_NAME',
                        index: 'USER_NAME'
                    },
                    {
                        name: 'OPERATOR_TIME',
                        index: 'OPERATOR_TIME'
                    }
                ],
                rownumbers: true, //自动行数
                autowidth:true,  //宽度自适应
                viewrecords: true,
                rowNum : 500,//一页显示多少条
                altRows: true,
                multiselect: true,
                multiboxonly: false,
                loadComplete: function (data) {
                },
                caption: "采购审核"
            });
            $("#psearch").bind('click',function(){
	       		 var filters = {};
	             filters.limit = 10000;
	             filters.offset = 0;
	             filters.shopId=$("#shopName").val()||-1;
	       		 filters.state = 0;
	             jQuery(grid_selector).jqGrid('setGridParam', {
	                    postData: filters
	                }).trigger("reloadGrid");
	       	})
            $(window).triggerHandler('resize.jqGrid');//trigger window resize to make the grid get the correct size

        });
    });
  }
	
	var updateStateFunc = function(stateVal){
		var ids = $(grid_selector).jqGrid('getGridParam', 'selarrrow');
	    if(ids.length == 0){
	        layer.closeAll('loading');
	        layer.msg('提示：请选择审核订单信息',{icon:0})
	        return;
	    }
	    var params = [];
	    for(var i = 0;i < ids.length;i++){
	    	var rowData = $(grid_selector).jqGrid('getRowData', ids[i]);	
	    	var param = {};
	    	param["id"] = rowData["ID"];
	    	param["state"] = stateVal;
	    	params.push(param);
	    }
	    if($(this).hasClass("btn-default")){
	    	layer.closeAll('loading');
	        layer.msg('正在提交,请稍后...',{icon:0})
			return;
		}
	   $(this).removeClass("btn-success").addClass("btn-default");
       $.ajax({
            url: '${contextPath}/order/updatePurchaseOrderItem',
            type: 'post',
            data: {"params":JSON.stringify(params),"isState":1},
            success: function (data) {
                layer.msg('提示：审核成功',{icon:0});
    			$(grid_selector).trigger("reloadGrid");
    			$(this).removeClass("btn-default").addClass("btn-success");
            },
            error: function (error) {
                layer.closeAll('loading');
                $("#gridSave").removeClass("btn-default").addClass("btn-success");
            }
        })
	}
	$("#verpassBtn").bind('click',function(){updateStateFunc(1)})
	$("#vernopassBtn").bind('click',function(){updateStateFunc(2)})
	
</script>

<!-- 业务处理 -->
<script>


    function getShop(){
    	$.ajax({
            url: '${contextPath}/ktcount/getShops', //localhost:8080
            data:{"zoneCode":"","shopType":"\'中深\'"},
            type: 'post',
            success: function (data) {
               	var data = data.data;
    			var html = '';
            	for(var i = 0;i < data.length;i++){
            		html +='<option value="'+data[i]["shopId"]+'">'+data[i]["shopName"]+'</option>';
            	}
            	$("#shopName").html(html);
            	$('#shopName').selectpicker('refresh');
            	if(!("" == data || null == data)){
            		$("#shopName").selectpicker('val',data[0]["shopId"]);
            	}
            	getShopInStockItem();
            },
            error: function (error) {
                alert(error)
            }
        })
    }



    $(function () {
        getShop();
    })
</script>
<script type="application/javascript">

	
    $(document).one('ajaxloadstart.page', function (e) {
        $.jgrid.gridDestroy(grid_selector);
        $('.ui-jqdialog').remove();
    });

</script>
